var express = require('express');
var router = express.Router();
const Films = require('../models/Films');
/* GET home page. */
router.get('/', async function (req, res) {
    if(req.session.login){
        let selectpage = Number(req.query.page)
        if (isNaN(selectpage)) {
            selectpage = 1
        }
        const offset = (selectpage-1) * 6;

        const collection = await Films.queryCol(req.session.uid, offset);
        let jcol = JSON.parse(JSON.stringify(collection))

        res.render('collection', {
            nav:'收藏',
            jfilms: jcol,
            login: req.session.login,
            username: req.session.username,
            selectpage: selectpage,
        })
    }else{
        res.render("collection", {
            nav: '收藏',
            jfilms: {},
            login: req.session.login,
            username: req.session.username,
        })
    }
});


module.exports = router;